<%@page import="interfaces.DALException"%>
<%@page import="java.util.List"%>
<%@page import="dto_objects.*"%>
<%@page import="java.util.ArrayList"%>
<%@page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>

<% 
String login = "<form action=\"LoginServlet\">"+
		"Username:<br>"+
		"<input type=\"text\" name=\"un\"><br>"+
		"Password:<br>"+
		"<input type=\"text\" name=\"pw\">"+
		"<input type=\"submit\" value=\"log In\">"+
		"&nbsp;"+
		"</form>";
%>

<script type="text/javascript" src="../javascripts/jquery-latest.pack.js"></script>
<script type="text/javascript" src="../javascripts/popup.js"></script>

<jsp:useBean id="func" class="Function.FunctionWEB" scope="session"/>  

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
	<title>Main Page</title>
	<link rel="stylesheet" type="text/css" href="../NewStyle.css">
</head>
<body>
<div id="loginField" class="window">
	<form action="../LoginServlet">
			Username:
			<input type="text" name="un"><br>
			Password:
			<input type="text" name="pw"><br>
			<input type="submit" value="Log In">
		</form>	
		<br>
	<a href="#"class="close" align=right style="color: #333;text-align: right;text-decoration: none;">Close</a>
</div>	
	<div id=topBox>
			<div id=searchField>
				<form action="MainPage.jsp">
				<input type="text" name="searchText"> 
				<input type="submit" value="">
				<a id="aSearchButton" href="../Search/aSearch.jsp">Advanced search</a>
				</form>			
			</div>
	
			<div id=login>
				<%out.print(func.getClass().getName());
				if(session.getAttribute("currentSessionUser") == null){
					session.setAttribute("userMENU", null);
					out.print("<a class=myButton href=\"#loginField\" name=\"loginFieldClick\">Login</a>");
				}else{
					out.print("<form action=\"../LoginServlet\">"+
							"<input class=myButton type=\"submit\" value=\"Log Out\" name=\"logout\">"+
							"</form>");
				}
				%>
			</div>
	</div>
	<div id=main>
		<div id=header>

		</div>
		<div id=content>
			<div id=data>
		<%
if (request.getMethod().equals("GET") && request.getParameter("searchText") != null){
	if(func.quickSearch(request.getParameter("searchText")) != null){
	ArrayList<ArrayList> searchList = func.quickSearch(request.getParameter("searchText"));
	
	for(int x=0;x<=searchList.size();x++){
		switch (x) {
	    case 0: 
	    	ArrayList<BookDTO> bookList = searchList.get(x);
	    	if(bookList.size() == 0)
	    		break;
	    	out.print("<p style=\"font-size:18pt;\">Boger</p><hr>");
	   		for(BookDTO tempBook : bookList){
	   			out.print("<br><img style=\"padding-right: 20px; padding-left: 20px;\" align=\"left\" src=\"../images/temp.jpg\" alt=\"Error\" height=\"200\" width=\"150\">");
	   			out.print("<a href=\"showBook.jsp?ISBN="+tempBook.getISBN()+"\">"+tempBook.getTitle()+"</a><br>");
	   			out.print("<span>Forfatter: </span>"+tempBook.getAuthorNames()+"<br>");
	   			out.print("<span>Udgiver: </span>"+tempBook.getPublisher().getPublisher_name()+"<br>");
	   			out.print("<span>Subject: </span>"+tempBook.getSubjectNames()+"<br>");
	   			out.print("<span>Sider: </span>"+tempBook.getPages()+"<br>");
	   			out.print("<br><br><br><br><br><hr>");
	   		}
	             break;
	    case 1: 
	    	ArrayList<AuthorDTO> authorList = searchList.get(x);
	    	if(authorList.size() == 0)
	    		break;
	    	out.print("<br><p style=\"font-size:18pt;\">Forfatter</p><hr>");
	   		for(AuthorDTO tempAuthor : authorList){
	   			out.print("<br><img style=\"padding-right: 20px; padding-left: 20px;\" align=\"left\" src=\"../images/pers.jpg\" alt=\"Error\" height=\"200\" width=\"150\">");
	   			out.print("<a href=\"showAuthor.jsp?authorID="+tempAuthor.getAuthorId()+"\">"+tempAuthor.getAuthorFirstName()+" "+tempAuthor.getAuthorLastName()+"</a><br>");
	   			out.print("<span>Forfatter ID: </span>"+tempAuthor.getAuthorId()+"<br><br><br>");
	   			out.print("<br><br><br><br><br><hr><br>");
	   		}
	             break;     
	    case 2: 
	    	ArrayList<SubjectDTO> subjectList = searchList.get(x);
	    	if(subjectList.size() == 0)
	    		break;
	    	out.print("<br><p style=\"font-size:18pt;\">Emner</p><br><hr>");
	   		for(SubjectDTO tempSubject : subjectList){
	   			out.print("<br><img style=\"padding-right: 20px; padding-left: 20px;\" align=\"left\" src=\"../images/subjects.jpg\" alt=\"Error\" height=\"200\" width=\"150\">");
	   			out.print("<a href=\"showSubject.jsp?subjectID="+tempSubject.getSubjectID()+"\">"+tempSubject.getSubject_name()+"</a><br>");
	   			out.print("<span>Subject ID: </span>"+tempSubject.getSubjectID()+"<br><br><br>");
	   			out.print("<br><br><br><br><br><hr><br>");
	   		}
	             break; 
	    case 3: 
	    	ArrayList<PublisherDTO> publisherList = searchList.get(x);
	    	if(publisherList.size() == 0)
	    		break;
	    	out.print("<br><p style=\"font-size:18pt;\">Udgiver</p><br><hr>");
	   		for(PublisherDTO tempPublisher : publisherList){
	   			out.print("<br><img style=\"padding-right: 20px; padding-left: 20px;\" align=\"left\" src=\"../images/publisher.jpg\" alt=\"Error\" height=\"200\" width=\"150\">");
	   			out.print("<a href=\"showPublisher.jsp?publisherID="+tempPublisher.getPublisherID()+"\">"+tempPublisher.getPublisher_name()+"</a><br>");
	   			out.print("<span>Publisher ID: </span>"+tempPublisher.getPublisherID()+"<br><br><br>");
	   			out.print("<br><br><br><br><br><hr><br>");
	   		}
	             break; 
	             
	    default:
	    	out.print("<br>");
	   			 break;
			}
		}
	}
}


%>		
		</div>
		${userMENU}
		</div>
	</div>
<div id="mask"></div>

</body>
</html>